package com.cskaoyan.mall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.TrademarkDTO;
import com.cskaoyan.mall.product.dto.TrademarkListDTO;
import com.cskaoyan.mall.product.model.Trademark;
import com.cskaoyan.mall.product.query.TrademarkParam;
import com.cskaoyan.mall.product.service.TrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Macro_Ray
 * @Since 2024/6/7 下午3:58
 */
@RestController
@RequestMapping("/admin/product/baseTrademark/")
public class TrademarkController {

    @Autowired
    TrademarkService trademarkService;

    /**
     * 分页查询品牌列表
     */
    @GetMapping("{page}/{limit}")
    public Result<TrademarkListDTO> getTrademarkList(@PathVariable("page") Integer page,
                                                     @PathVariable("limit") Integer limit) {
        Page<Trademark> pageParam = new Page<>(page, limit);
        TrademarkListDTO trademarkList = trademarkService.getTrademarkList(pageParam);
        return Result.ok(trademarkList);
    }

    /**
     * 添加品牌
     */
    @PostMapping("save")
    public Result saveTrademark(@RequestBody Trademark trademark) {
        trademarkService.saveTrademark(trademark);
        return Result.ok();
    }

    @GetMapping("get/{id}")
    public Result<TrademarkDTO> getTrademark(@PathVariable("id") Long id) {
        TrademarkDTO trademarkDTO = trademarkService.getTrademarkById(id);
        return Result.ok(trademarkDTO);
    }

    @PutMapping("update")
    public Result updateTrademark(@RequestBody TrademarkParam trademarkParm) {
        trademarkService.updateTrademark(trademarkParm);
        return Result.ok();
    }

    @DeleteMapping("remove/{id}")
    public Result removeTrademark(@PathVariable("id") Long id) {
        trademarkService.removeTrademarkById(id);
        return Result.ok();
    }
}
